package zy.blue7.im.gui;

import io.netty.channel.Channel;
import zy.blue7.im.Client;
import zy.blue7.im.common.message.LoginMessage;

import javax.swing.*;

/**
 * @author blue7
 * @version 1.0
 * @date 2022/3/1 16:42
 */
public class Main {
    private JButton login;
    private JTextField fromField;
    private JPanel root;
    private Channel channel;

    public Main() throws InterruptedException {
        channel = new Client().startClient();

        login.addActionListener(e -> {
            LoginMessage loginMessage = new LoginMessage();
            loginMessage.setFrom(fromField.getText());
            loginMessage.setTo("lisi");
            loginMessage.setUsername(fromField.getText());
            loginMessage.setPassword("123456");
            loginMessage.setContent(fromField.getText() + " 登录了。。。");
            channel.writeAndFlush(loginMessage);
        });
    }

    public static void main(String[] args) throws InterruptedException {
        JFrame frame = new JFrame("Main");
        frame.setContentPane(new Main().root);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1000, 800);
        frame.setLocation(500,200);
        frame.setVisible(true);
    }
}
